<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <title>五脉天罡3D</title>
    <style>
        html, body {
            height: 100%;
        }

        body {
            background-color: #000000;
            margin: 0;
            font-family: Helvetica, sans-serif;;
            overflow: hidden;
        }

        a {
            color: #ffffff;
        }

        #info {
            position: absolute;
            width: 100%;
            color: #ffffff;
            padding: 5px;
            font-family: Monospace;
            font-size: 13px;
            font-weight: bold;
            text-align: center;
            z-index: 1;
        }

        #menu {
            position: absolute;
            bottom: 20px;
            width: 100%;
            text-align: center;
            font-family: verdana,Tahoma,Arial,Hei,"Microsoft Yahei",SimHei;
        }

        .element {
            width: 120px;
            height: 160px;
            box-shadow: 0px 0px 12px rgba(0,255,255,0.5);
            border: 1px solid rgba(127,255,255,0.25);
            text-align: center;
            cursor: default;
        }

        .element:hover {
            box-shadow: 0px 0px 12px rgba(0,255,255,0.75);
            border: 1px solid rgba(127,255,255,0.75);
        }

        .element .number {
            position: absolute;
            top: 20px;
            right: 20px;
            font-size: 12px;
            color: rgba(127,255,255,0.75);
        }

        .element .symbol {
            position: absolute;
            top: 40px;
            left: 0px;
            right: 0px;
            font-size: 60px;
            font-weight: bold;
            color: rgba(255,255,255,0.75);
            text-shadow: 0 0 10px rgba(0,255,255,0.95);
        }

        .element .details {
            position: absolute;
            bottom: 15px;
            left: 0px;
            right: 0px;
            font-size: 12px;
            color: rgba(127,255,255,0.75);
        }

        button {
            color: rgba(127,255,255,0.75);
            background: transparent;
            outline: 1px solid rgba(127,255,255,0.75);
            border: 0px;
            padding: 5px 10px;
            cursor: pointer;
        }
        button:hover {
            background-color: rgba(0,255,255,0.5);
        }
        button:active {
            color: #000000;
            background-color: rgba(0,255,255,0.75);
        }
    </style>
</head>
<body>
<script src="/js/3d/three.min.js" ></script>
<script src="/js/3d/tween.min.js" ></script>
<script src="/js/3d/TrackballControls.js" ></script>
<script src="/js/3d/CSS3DRenderer.js" ></script>
<script src="/js/jquery.min.js" ></script>

<div id="container"></div>
<div id="info">五脉天罡3D</div>
<div id="menu">
    <button id="table">表面</button>
    <button id="sphere">球体</button>
    <button id="helix">螺旋</button>
    <button id="grid">网格</button>
    <button id="paycontrols" class="play" >暂停</button>
    <button onclick="topage()" class="play" >进入</button>
</div>
<audio id="audioId" autoplay preload="auto" src="http://linjiexiantools.cn-gd.ufileos.com/Victory.mp3" type="audio/mpeg">
    Your browser does not support the audio tag.
</audio>
<script>

    var audio = document.getElementById("audioId");
    $("#paycontrols").click(function() {
        if ($("#paycontrols").hasClass("play")) {
            audio.pause();
            $("#paycontrols").addClass("pause").removeClass("play");
            $("#paycontrols").html("播放");
        } else {
            audio.play();//开始播放
            $("#paycontrols").addClass("play").removeClass("pause");
            $("#paycontrols").html("暂停");

        }
    })

    var table = [
        "乾", "Hydrogen", "1.00794", 1, 1,
        "坤", "Helium", "4.002602", 18, 1,
        "屯", "Lithium", "#6.941", 1, 2,
        "蒙", "Beryllium", "9.012182", 2, 2,
        "需", "Boron", "#10.811", 13, 2,
        "讼", "Carbon", "#12.0107", 14, 2,
        "师", "Nitrogen", "#14.0067", 15, 2,
        "比", "Oxygen", "#15.9994", 16, 2,
        "小畜", "Fluorine", "18.9984032", 17, 2,
        "履", "Neon", "#20.1797", 18, 2,
        "泰", "Sodium", "22.98976...", 1, 3,
        "否", "Magnesium", "#24.305", 2, 3,
        "同人", "Aluminium", "26.9815386", 13, 3,
        "大有", "Silicon", "#28.0855", 14, 3,
        "谦", "Phosphorus", "30.973762", 15, 3,
        "豫", "Sulfur", "#32.065", 16, 3,
        "随", "Chlorine", "#35.453", 17, 3,
        "蛊", "Argon", "#39.948", 18, 3,
        "临", "Potassium", "#39.948", 1, 4,
        "观", "Calcium", "#40.078", 2, 4,
        "噬嗑", "Scandium", "44.955912", 3, 4,
        "贲", "Titanium", "#47.867", 4, 4,
        "剥", "Vanadium", "#50.9415", 5, 4,
        "复", "Chromium", "#51.9961", 6, 4,
        "无妄", "Manganese", "54.938045", 7, 4,
        "大畜", "Iron", "#55.845", 8, 4,
        "颐", "Cobalt", "58.933195", 9, 4,
        "大过", "Nickel", "#58.6934", 10, 4,
        "坎", "Copper", "#63.546", 11, 4,
        "离", "Zinc", "#65.38", 12, 4,
        "咸", "Gallium", "#69.723", 13, 4,
        "恒", "Germanium", "#72.63", 14, 4,
        "遁", "Arsenic", "#74.9216", 15, 4,
        "大壮", "Selenium", "#78.96", 16, 4,
        "晋", "Bromine", "#79.904", 17, 4,
        "明夷", "Krypton", "#83.798", 18, 4,
        "家人", "Rubidium", "#85.4678", 1, 5,
        "睽", "Strontium", "#87.62", 2, 5,
        "蹇", "Yttrium", "88.90585", 3, 5,
        "解", "Zirconium", "#91.224", 4, 5,
        "损", "Niobium", "92.90628", 5, 5,
        "益", "Molybdenum", "#95.96", 6, 5,
        "夬", "Technetium", "(98)", 7, 5,
        "姤", "Ruthenium", "#101.07", 8, 5,
        "萃", "Rhodium", "#102.9055", 9, 5,
        "升", "Palladium", "#106.42", 10, 5,
        "困", "Silver", "#107.8682", 11, 5,
        "井", "Cadmium", "#112.411", 12, 5,
        "革", "Indium", "#114.818", 13, 5,
        "鼎", "Tin", "#118.71", 14, 5,
        "震", "Antimony", "#121.76", 15, 5,
        "艮", "Tellurium", "127.6", 16, 5,
        "渐", "Iodine", "126.90447", 17, 5,
        "归妹", "Xenon", "#131.293", 18, 5,
        "丰", "Caesium", "#132.9054", 1, 6,
        "旅", "Barium", "#132.9054", 2, 6,
        "巽", "Lanthanum", "138.90547", 4, 9,
        "兑", "Cerium", "#140.116", 5, 9,
        "涣", "Praseodymium", "140.90765", 6, 9,
        "节", "Neodymium", "#144.242", 7, 9,
        "中孚", "Promethium", "(145)", 8, 9,
        "小过", "Samarium", "#150.36", 9, 9,
        "既济", "Europium", "#151.964", 10, 9,
        "未济", "Gadolinium", "#157.25", 11, 9,
        "天罡", "Terbium", "158.92535", 12, 9,
        "重光", "Dysprosium", "162.5", 13, 9,
        "九天", "Holmium", "164.93032", 14, 9,
        "九地", "Erbium", "#167.259", 15, 9,
        "空", "Thulium", "168.93421", 16, 9,
        "甪端", "Ytterbium", "#173.054", 17, 9,
        "虚耗", "Lutetium", "#174.9668", 18, 9,
        "傲狠", "Hafnium", "#178.49", 4, 6,
        "九婴", "Tantalum", "180.94788", 5, 6,
        "白泽", "Tungsten", "#183.84", 6, 6,
        "蜚瘟", "Rhenium", "#186.207", 7, 6,
        "朱厌", "Osmium", "#190.23", 8, 6,
        "穷奇", "Iridium", "#192.217", 9, 6,
        "隗知", "Platinum", "#195.084", 10, 6,
        "狞", "Gold", "196.966569", 11, 6,
        "狍鸮", "Mercury", "#200.59", 12, 6,
        "壁宿", "Thallium", "#204.3833", 13, 6,
        "室宿", "Lead", "207.2", 14, 6,
        "危宿", "Bismuth", "#208.9804", 15, 6,
        "斗宿", "Polonium", "(209)", 16, 6,
        "氐宿", "Astatine", "(210)", 17, 6,
        "房宿", "Radon", "(222)", 18, 6,
        "轸宿", "Francium", "(223)", 1, 7,
        "翼宿", "Radium", "(226)", 2, 7,
        "张宿", "Actinium", "(227)", 4, 10,
        "星宿", "Thorium", "232.03806", 5, 10,
        "柳宿", "Protactinium", "#231.0588", 6, 10,
        "鬼宿", "Uranium", "238.02891", 7, 10,
        "井宿", "Neptunium", "(237)", 8, 10,
        "参宿", "Plutonium", "(244)", 9, 10,
        "觜宿", "Americium", "(243)", 10, 10,
        "毕宿", "Curium", "(247)", 11, 10,
        "昴宿", "Berkelium", "(247)", 12, 10,
        "胃宿", "Californium", "(251)", 13, 10,
        "娄宿", "Einstenium", "(252)", 14, 10,
        "奎宿", "Fermium", "(257)", 15, 10,
        "九婴", "Mendelevium", "(258)", 16, 10,
        "诸怀", "Nobelium", "(259)", 17, 10,
        "飞廉", "Lawrencium", "(262)", 18, 10,
        "魑", "Rutherfordium", "(267)", 4, 7,
        "魅", "Dubnium", "(268)", 5, 7,
        "魍", "Seaborgium", "(271)", 6, 7,
        "魉", "Bohrium", "(272)", 7, 7,
        "开门", "Hassium", "(270)", 8, 7,
        "白虎", "Meitnerium", "(276)", 9, 7,
        "玄武", "Darmstadium", "(281)", 10, 7,
        "朱雀", "Roentgenium", "(280)", 11, 7,
        "腾蛇", "Copernicium", "(285)", 12, 7,
        "六合", "Unutrium", "(284)", 13, 7,
        "青龙", "Flerovium", "(289)", 14, 7,
        "直符", "Ununpentium", "(288)", 15, 7,
        "生门", "Livermorium", "(293)", 16, 7,
        "太阴", "Ununseptium", "(294)", 17, 7,
        "太阳", "Ununoctium", "(294)", 18, 7
    ];

    var camera, scene, renderer;
    var controls;

    var objects = [];
    var targets = { table: [], sphere: [], helix: [], grid: [] };

    init();
    animate();

    function init() {

        camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
        camera.position.z = 3000;

        scene = new THREE.Scene();

        // table

        for ( var i = 0; i < table.length; i += 5 ) {

            var element = document.createElement( 'div' );
            element.className = 'element';
            element.style.backgroundColor = 'rgba(0,127,127,' + ( Math.random() * 0.5 + 0.25 ) + ')';
            var createOnclick = document.createAttribute("onclick"); //创建属性
            var parms= 'showView(\"'+i+'\")';
            createOnclick.value = parms; //设置属性值
            element.setAttributeNode(createOnclick); //给div添加属性

            var number = document.createElement( 'div' );
            number.className = 'number';
            number.textContent = (i/5) + 1;
            element.appendChild( number );

            var symbol = document.createElement( 'div' );
            symbol.className = 'symbol';
            symbol.textContent = table[ i ];
            element.appendChild( symbol );

            var details = document.createElement( 'div' );
            details.className = 'details';
            details.innerHTML = table[ i + 1 ] + '<br>' + table[ i + 2 ];
            element.appendChild( details );

            var object = new THREE.CSS3DObject( element );
            object.position.x = Math.random() * 4000 - 2000;
            object.position.y = Math.random() * 4000 - 2000;
            object.position.z = Math.random() * 4000 - 2000;
            scene.add( object );

            objects.push( object );

            //

            var object = new THREE.Object3D();
            object.position.x = ( table[ i + 3 ] * 140 ) - 1330;
            object.position.y = - ( table[ i + 4 ] * 180 ) + 990;

            targets.table.push( object );

        }

        // sphere

        var vector = new THREE.Vector3();

        for ( var i = 0, l = objects.length; i < l; i ++ ) {

            var phi = Math.acos( -1 + ( 2 * i ) / l );
            var theta = Math.sqrt( l * Math.PI ) * phi;

            var object = new THREE.Object3D();

            object.position.x = 800 * Math.cos( theta ) * Math.sin( phi );
            object.position.y = 800 * Math.sin( theta ) * Math.sin( phi );
            object.position.z = 800 * Math.cos( phi );

            vector.copy( object.position ).multiplyScalar( 2 );

            object.lookAt( vector );

            targets.sphere.push( object );

        }

        // helix

        var vector = new THREE.Vector3();

        for ( var i = 0, l = objects.length; i < l; i ++ ) {

            var phi = i * 0.175 + Math.PI;

            var object = new THREE.Object3D();

            object.position.x = 900 * Math.sin( phi );
            object.position.y = - ( i * 8 ) + 450;
            object.position.z = 900 * Math.cos( phi );

            vector.x = object.position.x * 2;
            vector.y = object.position.y;
            vector.z = object.position.z * 2;

            object.lookAt( vector );

            targets.helix.push( object );

        }

        // grid

        for ( var i = 0; i < objects.length; i ++ ) {

            var object = new THREE.Object3D();

            object.position.x = ( ( i % 5 ) * 400 ) - 800;
            object.position.y = ( - ( Math.floor( i / 5 ) % 5 ) * 400 ) + 800;
            object.position.z = ( Math.floor( i / 25 ) ) * 1000 - 2000;

            targets.grid.push( object );

        }

        //

        renderer = new THREE.CSS3DRenderer();
        renderer.setSize( window.innerWidth, window.innerHeight );
        renderer.domElement.style.position = 'absolute';
        document.getElementById( 'container' ).appendChild( renderer.domElement );

        //

        controls = new THREE.TrackballControls( camera, renderer.domElement );
        controls.rotateSpeed = 0.5;
        controls.minDistance = 500;
        controls.maxDistance = 6000;
        controls.addEventListener( 'change', render );

        var button = document.getElementById( 'table' );
        button.addEventListener( 'click', function ( event ) {

            transform( targets.table, 2000 );

        }, false );

        var button = document.getElementById( 'sphere' );
        button.addEventListener( 'click', function ( event ) {

            transform( targets.sphere, 2000 );

        }, false );

        var button = document.getElementById( 'helix' );
        button.addEventListener( 'click', function ( event ) {

            transform( targets.helix, 2000 );

        }, false );

        var button = document.getElementById( 'grid' );
        button.addEventListener( 'click', function ( event ) {

            transform( targets.grid, 2000 );

        }, false );

        transform( targets.table, 5000 );

        //

        window.addEventListener( 'resize', onWindowResize, false );

    }

    function transform( targets, duration ) {

        TWEEN.removeAll();

        for ( var i = 0; i < objects.length; i ++ ) {

            var object = objects[ i ];
            var target = targets[ i ];

            new TWEEN.Tween( object.position )
                .to( { x: target.position.x, y: target.position.y, z: target.position.z }, Math.random() * duration + duration )
                .easing( TWEEN.Easing.Exponential.InOut )
                .start();

            new TWEEN.Tween( object.rotation )
                .to( { x: target.rotation.x, y: target.rotation.y, z: target.rotation.z }, Math.random() * duration + duration )
                .easing( TWEEN.Easing.Exponential.InOut )
                .start();

        }

        new TWEEN.Tween( this )
            .to( {}, duration * 2 )
            .onUpdate( render )
            .start();

    }

    function onWindowResize() {

        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();

        renderer.setSize( window.innerWidth, window.innerHeight );

        render();

    }

    function animate() {

        requestAnimationFrame( animate );

        TWEEN.update();

        controls.update();

    }

    function render() {

        renderer.render( scene, camera );

    }

    function showView(index){
        //alert(index);
    }

    function topage(){
        window.location.href="/idx";
    }

    console.info("由五脉弟子刘玮制作！！！");

</script>
</body>
</html>
